package com.sleep.psy.external_server.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//
//@Configuration
//@MapperScan(basePackages = SecondDatabaseConfig.PACKAGE, sqlSessionFactoryRef = "secondSqlSessionFactory")
//public class SecondDatabaseConfig {
//
//    @Autowired
//    private PaginationInterceptor paginationInterceptor;
//
//    @Autowired
//    private PerformanceInterceptor performanceInterceptor;
//
//    // 精确到 master 目录，以便跟其他数据源隔离
//    static final String PACKAGE = "com.lkhd.base_project.business2.*.mapper";
//    static final String MAPPER_LOCATION = "classpath*:mapper2/*.xml";
//
//    @Value("${second.datasource.url}")
//    private String url;
//
//    @Value("${second.datasource.username}")
//    private String user;
//
//    @Value("${second.datasource.password}")
//    private String password;
//
//    @Value("${second.datasource.driverClassName}")
//    private String driverClass;
//
//    @Bean(name = "secondDataSource")
//    public DataSource secondDataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setDriverClassName(driverClass);
//        dataSource.setUrl(url);
//        dataSource.setUsername(user);
//        dataSource.setPassword(password);
//        return dataSource;
//    }
//
//    @Bean(name = "secondTransactionManager")
//    public DataSourceTransactionManager secondTransactionManager() {
//        return new DataSourceTransactionManager(secondDataSource());
//    }
//
//    @Bean("secondSqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("secondDataSource") DataSource dataSource) throws Exception {
//
//        MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource(dataSource);
//        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper2/*.xml"));
//        Interceptor[] plugins = {paginationInterceptor,performanceInterceptor};
//        sqlSessionFactoryBean.setPlugins(plugins);
//        return sqlSessionFactoryBean.getObject();
//
//    }
//
//}
